eststo clear
local S 0 1 
foreach s of local S {
capture drop b_in_sample
bys b_id: egen b_in_sample=max(SAMPLE_`s')    
local VAR ALL_sourcing_metric_b 
foreach v of local VAR{
capture drop S_`v'	
capture drop xx
capture drop mean_xx
capture drop sd_xx
gen xx=`v' if n_b==1 & b_in_sample==1 & `v'!=0
egen mean_xx=mean(xx)
egen sd_xx=sd(xx)
gen S_`v'=(`v'-mean_xx)/sd_xx
replace S_`v'=. if `v'==0
replace S_`v'=. if b_in_sample!=1    
label var S_`v' "\${Relational}_{b}\$" 

eststo: reghdfe ln_p_tr S_`v' ln_q_sb_all sh_s_b sh_b_s age_buysel_month signatory  ///
 ln_q_b_all age_buy_month   ln_q_tr   if SAMPLE_`s'==1, ///
 abs(gr_sjt top_dest_b cohort_sb cohort_b) vce (cluster b_id)
  quietly estadd local CTRL ="\scriptsize{B,R,O}", replace  
  quietly estadd local SAMP ="(`s')", replace  
  quietly estadd local FE ="sjt,d", replace  
  quietly estadd local CTRL2 ="All", replace    
  quietly estadd scalar  U =  . , replace     
}			
} 
local S 2 3 4 5 
foreach s of local S {
capture drop b_in_sample
bys b_id: egen b_in_sample=max(SAMPLE_`s')    
local VAR sourcing_metric_b_excl 
foreach v of local VAR{
capture drop S_`v'	
capture drop xx
capture drop mean_xx
capture drop sd_xx
gen xx=`v' if n_b==1 & b_in_sample==1 & `v'!=0
egen mean_xx=mean(xx)
egen sd_xx=sd(xx)
gen S_`v'=(`v'-mean_xx)/sd_xx
replace S_`v'=. if `v'==0
replace S_`v'=. if b_in_sample!=1    
label var S_`v' "\${Relational}_{b}\$" 

eststo: reghdfe ln_p_tr S_`v' ln_q_sb_all sh_s_b sh_b_s age_buysel_month signatory  ///
 ln_q_b_all age_buy_month   ln_q_tr   if SAMPLE_`s'==1, ///
 abs(gr_sjt top_dest_b cohort_sb cohort_b) vce (cluster b_id)
  quietly estadd local CTRL ="\scriptsize{B,R,O}", replace  
  quietly estadd local SAMP ="(`s')", replace  
  quietly estadd local FE ="sjt,d", replace  
  quietly estadd local CTRL2 ="Excluded", replace    
  quietly estadd scalar  U =  . , replace     
}			
}
esttab using "${tables}\TableD4PanelA.tex", ///
  label replace booktabs b(3) se(3) noconstant obslast substitute(\_ _) ///
      title("Prices of Transactions and Sourcing Across Samples" \label{TransactionsRobustness}) ///
  drop(ln_q_sb_all sh_s_b sh_b_s age_buysel_months ln_q_b_all age_buy_months  signatory ln_q_tr _cons   ) order(    ) /// 
  stats(FE CTRL SAMP CTRL2  r2   N   , fmt( %~#s %~#s %~#s %~#s   2 %12.0fc  )  ///
  labels("FEs" "Controls" "Sample" "Relational Metric"  `"\(R^{2}\)"'  "Obs."  ))   ///
  star(* 0.10 ** 0.05 *** 0.01) ///
  nonotes   
  
  
eststo clear
local S 3 4 5 
foreach s of local S {
capture drop b_in_sample
bys b_id: egen b_in_sample=max(SAMPLE_`s')    

local VAR sourcing_metric_b_excl 
foreach v of local VAR{
capture drop S_`v'	
capture drop xx
capture drop mean_xx
capture drop sd_xx
gen xx=`v' if n_b==1 & b_in_sample==1 & `v'!=0
egen mean_xx=mean(xx)
egen sd_xx=sd(xx)
gen S_`v'=(`v'-mean_xx)/sd_xx
replace S_`v'=. if `v'==0
replace S_`v'=. if b_in_sample!=1    
label var S_`v' "\${Relational}_{b}\$" 

eststo: reghdfe ln_p_sbjo S_`v' ln_q_sb_all sh_s_b sh_b_s age_buysel_month signatory  ///
 ln_q_b_all age_buy_month   ln_q_sbjo ln_p_inpf_sbjo    if SAMPLE_`s'==1 & n_ud==1, ///
 abs(gr_sjt top_dest_b cohort_sb cohort_b) vce (cluster b_id)
  quietly estadd local CTRL ="\scriptsize{B,R,O}", replace  
  quietly estadd local SAMP ="(`s')", replace  
  quietly estadd local FE ="sjt,d", replace  
  quietly estadd local CTRL2 ="Excluded", replace    
  quietly estadd scalar  U =  . , replace      
}				
}
esttab using "${tables}\TableD4PanelB.tex", ///
  label replace booktabs b(3) se(3) noconstant obslast substitute(\_ _) ///
      title("Prices of Transactions and Sourcing Across Samples" \label{TransactionsRobustness}) ///
  drop(ln_q_sb_all sh_s_b sh_b_s age_buysel_months ln_q_b_all age_buy_months  signatory ln_q_sbjo ln_p_inpf_sbjo  _cons   ) order(    ) /// 
  stats(FE CTRL SAMP CTRL2  r2   N   , fmt( %~#s %~#s %~#s %~#s   2 %12.0fc  )  ///
  labels("FEs" "Controls" "Sample" "Relational Metric"  `"\(R^{2}\)"'  "Obs."  ))   ///
  star(* 0.10 ** 0.05 *** 0.01) ///
  nonotes 
  
eststo clear
local S 3 4 5 
foreach s of local S {
capture drop b_in_sample
bys b_id: egen b_in_sample=max(SAMPLE_`s')    

local VAR sourcing_metric_b_excl incl_sourcing_metric_b
foreach v of local VAR{
capture drop S_`v'	
capture drop xx
capture drop mean_xx
capture drop sd_xx
gen xx=`v' if n_b==1 & b_in_sample==1 & `v'!=0
egen mean_xx=mean(xx)
egen sd_xx=sd(xx)
gen S_`v'=(`v'-mean_xx)/sd_xx
replace S_`v'=. if `v'==0
replace S_`v'=. if b_in_sample!=1    
label var S_`v' "\${Relational}_{b}\$" 

eststo: reghdfe ln_mu_sbjo S_`v' ln_q_sb_all sh_s_b sh_b_s age_buysel_month signatory  ///
 ln_q_b_all age_buy_month   ln_q_sbjo ln_p_inpf_sbjo    if SAMPLE_`s'==1 & n_ud==1, ///
 abs(gr_sjt top_dest_b cohort_sb cohort_b) vce (cluster b_id)
  quietly estadd local CTRL ="\scriptsize{B,R,O}", replace  
  quietly estadd local SAMP ="(`s')", replace  
  quietly estadd local FE ="sjt,d", replace  
  quietly estadd local CTRL2 ="Excluded", replace    
  quietly estadd scalar  U =  . , replace      
}				
}
esttab using "${tables}\TableD4PanelC.tex", ///
  label replace booktabs b(3) se(3) noconstant obslast substitute(\_ _) ///
      title("Prices of Transactions and Sourcing Across Samples" \label{TransactionsRobustness}) ///
  drop(ln_q_sb_all sh_s_b sh_b_s age_buysel_months ln_q_b_all age_buy_months  signatory ln_q_sbjo ln_p_inpf_sbjo  _cons   ) order(    ) /// 
  stats(FE CTRL SAMP CTRL2  r2   N   , fmt( %~#s %~#s %~#s %~#s   2 %12.0fc  )  ///
  labels("FEs" "Controls" "Sample" "Relational Metric"  `"\(R^{2}\)"'  "Obs."  ))   ///
  star(* 0.10 ** 0.05 *** 0.01) ///
  nonotes 